<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('报警管理')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>编号：</label>
                            <input type="text" name="code"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success single disabled" onclick="alert()" shiro:hasPermission="boat:alert:edit">
                <i class="fa fa-exclamation-triangle"></i> 报警设置
            </a>
            <a class="btn btn-primary single disabled" onclick="user()" shiro:hasPermission="boat:alert:edit">
                <i class="fa fa-user"></i> 通知人员
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var alertFlag = [[${@permission.hasPermi('boat:alert:edit')}]];
    var prefix = ctx + "boat/alert";

    let boats
    $(function () {
        var options = {
            url: ctx + "boat/boat/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "波浪艇",
            singleSelect: true,
            columns: [
                {
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'name',
                    title: '名称'
                },
                {
                    field: 'code',
                    title: '编号'
                },
                {
                    field: 'card',
                    title: '北斗卡号'
                },
                {
                    field: 'dept.deptName',
                    title: '所属机构'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + alertFlag + '" href="javascript:void(0)" onclick="alert(\'' + row.id + '\')"><i class="fa fa-exclamation-triangle"></i> 报警</a> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + alertFlag + '" href="javascript:void(0)" onclick="user(\'' + row.id + '\')"><i class="fa fa-user"></i> 人员</a> ');
                        return actions.join(' ');
                    }
                }]
        };
        $.table.init(options);
    });

    function getRow(id) {
        table.set();
        if ($.common.isEmpty(id)) {
            id = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (id.length === 0) {
                $.modal.alertWarning("请选择一条记录");
                return null;
            }
        }
        let rows = $("#bootstrap-table").bootstrapTable('getData');
        return rows.find(r => r.id == id); // 这里必须2个等号 因为每一行的按钮 传入的id是字符串
    }

    function alert(id) {
        var row = getRow(id);
        if (row) $.modal.open(`${row.name} ${row.code} 报警设置`, prefix + '/set/' + row.id);
    }

    function user(id) {
        var row = getRow(id);
        if (row) $.modal.open(`${row.name} ${row.code} 通知人员`, prefix + '/user/' + row.id, 620, 412);
    }

</script>
</body>
</html>